package com.sunhao.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.sunhao.myapplication.utils.DateUtil;

public class MainActivity9 extends AppCompatActivity implements View.OnClickListener {


    private View tv_result;
    private TextView test;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main9);
        //获取4个元素
        TextView open = findViewById(R.id.open);
        TextView close = findViewById(R.id.close);
        test = findViewById(R.id.test);
        tv_result = findViewById(R.id.tv_result);

        //监听对应元素
        open.setOnClickListener(this);
        close.setOnClickListener(this);
        test.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
//        switch (view.getId()) {
//
//            case R.id.open:
//
//                break;
//            case R.id.close:
//
//                break;
//            case R.id.test:
//                String nowTime = DateUtil.getNowTime();
//                //获取结果
//                String desc=String.format("%s 您点击了按钮：%s",nowTime,((Button)view).getText());
//                ((TextView)tv_result).setText(desc);
//                break;
//        }
        if(view.getId()==R.id.open){
                test.setEnabled(true);
        }
        if(view.getId()==R.id.close){
            test.setEnabled(false);
        }
        if(view.getId()==R.id.test){
                String nowTime = DateUtil.getNowTime();
                //获取结果
                String desc=String.format("%s 您点击了按钮：%s",nowTime,((Button)view).getText());
                ((TextView)tv_result).setText(desc);
        }
    }
}